package com.hxzy.springbootes.es.service;

import com.hxzy.springbootes.es.entity.EsHotel;
import com.hxzy.springbootes.es.repository.EsHotelRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @Author gityyge
 * @Description TODO
 * @Date 2023/5/31 15:53
 * @Version 1.0
 */
@Service
public class EsHotalService {
    @Autowired
    private EsHotelRepository esHotelRepository;


    /**
     * 新增(把数据写入到es库里面)
     * @param esHotel
     */
    public void insert(EsHotel esHotel){
       this.esHotelRepository.save(esHotel);
    }

    public EsHotel findById(Long id) {
        Optional<EsHotel> optional = this.esHotelRepository.findById(id);
        if(optional.isPresent()){
            return optional.get();
        }else{
            return null;
        }
    }

    public boolean deleteById(Long id) {
        this.esHotelRepository.deleteById(id);
        return true;
    }
}
